<template>
  <div>
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item><a href="#">活动管理</a></el-breadcrumb-item>
      <el-breadcrumb-item>活动列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!--  输入框组-->
    <div>
      <br/>
      <span>活动名称 &nbsp;&nbsp;</span>
      <el-input
          placeholder="请输入活动名称"
          prefix-icon="el-icon-search"
          v-model="activity.name" class="inputMax" >
      </el-input>
      <span>&nbsp;&nbsp;活动地点&nbsp;&nbsp;</span>
      <el-input
          class="inputMax"
          placeholder="请输入活动地点"
          v-model="activity.place"
          prefix-icon="el-icon-location-information">
      </el-input>
      <span>&nbsp;&nbsp;活动类型&nbsp;&nbsp;</span>
      <el-select v-model="activity.type" placeholder="请选择" class="inputMax">
        <el-option
            v-for="item in activityTypes"
            :key="item.id"
            :label="item.name"
            :value="item.name">
        </el-option>
      </el-select>
      &nbsp;&nbsp;
      <el-button type="primary" icon="el-icon-search" @click="doActivitySearch" ><span>查询</span></el-button>
      <br/>
      <br/>
    </div>
    <el-table
        :data="activitys"
        border
        style="width: 100%">
      <el-table-column
          prop="id"
          label="ID"
          width="100">
      </el-table-column>
      <el-table-column
          prop="name"
          label="活动名称"
          width="100">
      </el-table-column>
      <el-table-column
          prop="place"
          label="活动地点"
          width="100">
      </el-table-column>
      <el-table-column
          prop="time"
          label="活动时间"
          width="100">
        <template slot-scope="scope">
          <span>{{scope.row.time | DateFormat}}</span>
        </template>
      </el-table-column>
      <el-table-column
          prop="type"
          label="活动类型"
          width="100">
      </el-table-column>
      <el-table-column
          prop="content"
          show-overflow-tooltip
          label="活动内容">
      </el-table-column>
      <el-table-column
          fixed="right"
          width="100"
          label="操作">
        <template slot-scope="scope">
          <el-button type="primary" icon="el-icon-search" size="mini" @click="toActivity(scope.row)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
        background
        layout="prev, pager, next"
        :page-size="pageSize"
        :total="total">
    </el-pagination>

    <el-dialog title="活动审核" :visible.sync="dialogFormVisible" :modal-append-to-body="false">
      <el-form :model="activityForm">
        <el-form-item label="活动名称" :label-width="formLabelWidth">
          <el-input v-model="activityForm.name" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="活动内容" :label-width="formLabelWidth">
          <el-input type="textarea" :rows="2" v-model="activityForm.content" autocomplete="off"></el-input>
        </el-form-item>
        <img :src="preUrl+activityForm.image" style="width: 100%;">
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="activityNoPass(activityForm)">打回</el-button>
        <el-button type="primary" @click="activityPass(activityForm)">通过</el-button>
      </div>

    </el-dialog>
  </div>
</template>

<script>
import {activityList, activityTypeList,activityUpdate} from "@/api";

export default {
  name: "ActivityList",
  components: {
  },
  data() {
    return {
      activitys:[],
      activity:{
        id: 0,
        name: '',
        place: '',
        content: '',
        time: '',
        image: '',
        type: '',
        status:1,
      },
      activityTypes: [],
      total: 0,
      pageSize: 5,
      activityForm:{},
      formLabelWidth: '120px',
      preUrl:'https://dayu-club.oss-cn-shenzhen.aliyuncs.com/',
      dialogTableVisible: false,
      dialogFormVisible: false,
    }
  },

  created() {
      activityTypeList().then((result)=>{
        this.activityTypes = result.data;
        this.activityTypes.unshift('');
      });

      activityList(this.activity).then((result)=>{
        this.activitys = result.data.list;
        this.total = result.data.total;
        this.pageSize = result.data.pagesize;
      })
  },

  methods: {

    doActivitySearch(){
      activityList(this.activity).then((result)=>{
        this.activitys = result.data.list;
        this.total = result.data.total;
        this.pageSize = result.data.pagesize;
      })
    },

    toActivity(activity){
      this.dialogFormVisible = true;
      this.activityForm = activity;
    },
    activityNoPass(activity){
      this.dialogFormVisible =false;
      activity.status =0;
      activityUpdate(activity).then(result=>{
        activityList({status:1}).then((result)=>{
          this.activitys = result.data.list;
          this.total = result.data.total;
          this.pageSize = result.data.pagesize;
        });
      });

    },
    activityPass(activity){
      this.dialogFormVisible =false;
      activity.status =2;
      activityUpdate(activity).then(result=>{
        activityList({status:1}).then((result)=>{
          this.activitys = result.data.list;
          this.total = result.data.total;
          this.pageSize = result.data.pagesize;
        });
      });
    }
  }
}
</script>

<style scoped>
.inputMax{
  width: 200px;
}
</style>
